package com.agile.leetcode.PriorityQueue;

import java.util.*;

/**
 * 测试优先队列的排序功能
 *
 * @Author:ChenZhangKun
 * @Date: 2021/5/26 22:21
 */
public class PriorityQueueTest4 {
    public static void main(String[] args) {
        PriorityQueue priorityQueue = new PriorityQueue();
        PriorityQueue priorityQueue2 = new PriorityQueue(Comparator.reverseOrder());
        // 创建随机对象
        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            // 优先队列添加此时天然有序
            priorityQueue.add(random.nextInt(100));
            priorityQueue2.add(random.nextInt(100));
        }
        List<Integer> list = new ArrayList<>(150);
        List<Integer> list2 = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add((Integer) priorityQueue.poll());
            list2.add((Integer) priorityQueue2.poll());
        }

        // 遍历是否有序
        System.out.println(Arrays.toString(list.toArray()));
        System.out.println();
        System.out.printf(Arrays.toString(list2.toArray()));
    }
}
